library(tidyverse)
library(skimr)
library(rethinking)
Linear regression describes a measurements mean and variance as the addition of other measurements. It assumes the errors in the primary measurement are of the gaussian distribution.
1000 individuals conduct a random walk on either side of the football field starting at the 50 yard line (value = 0). This signifies the normal distribution.
INDIVIDUALS <- 1000
TRIALS <- 100
purrr::map(1:INDIVIDUALS, ~ runif(TRIALS, -1, 1)) %>%
purrr::map(cumsum) %>%
reduce(rbind) %>%
as_tibble %>%
`colnames<-`(paste0(1:TRIALS, "t")) %>%
mutate(individual = row_number()) %>%
reshape2::melt("individual") %>%
arrange(individual, variable) %>%
ggplot(aes(x=variable, y=value, group=individual)) +
geom_line(alpha = I(1/20), size=1) +
geom_boxplot(aes(x=variable, y = value), inherit.aes = FALSE, colour = "yellow", alpha= I(1/40))